package com.xsd.awen.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xsd.awen.domain.entity.App;
import com.xsd.awen.domain.po.AppPagePo;
import com.xsd.awen.domain.vo.AppVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AppMapper extends BaseMapper<App> {

    @Select("<script> " +
            " select u.*,p.cname projectName from t_tk_app u" +
            " left join t_tk_project p on u.project_id = p.id" +
            " where 1=1  " +
            "<if test=\"app.name != null and app.name != ''\"> and u.name like CONCAT('%', #{app.name}, '%')</if>" +
            "<if test=\"app.projectId != null and app.projectId != ''\"> and u.project_id = #{app.projectId}</if>" +
            " order by u.create_time desc " +
            "</script>")
    List<AppPagePo> page(AppVo appVo);

    @Select(" select count(1) from t_tk_app where name = #{name} ")
    Integer countApp(App app);

    @Select(" select count(1) from t_tk_app where name = #{name} and id != #{id} ")
    Integer countUpdateApp(App app);

    @Select(" select count(1) from t_tk_app where project_id = #{projectId} ")
    Integer countAppByProjectId(App app);

}